home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / xlib05.zip / XMOUSE.ASM < prev    next >
Assembly Source File  |  1993-08-25  |  24KB  |  853 lines

  1. ;-----------------------------------------------------------------------
  2. ; MODULE XMOUSE
  3. ;
  4. ; Mouse functions functions for all MODE X 256 Color resolutions
  5. ;
  6. ; Compile with Tasm.
  7. ; C callable.
  8. ;
  9. ; ****** XLIB - Mode X graphics library                ****************
  10. ; ******                                               ****************
  11. ; ****** Written By Themie Gouthas                     ****************
  12. ;
  13. ; This module is based on Shane Hyde's module of the same name,
  14. ; posted to Rec.Games.Programmer, October 92.
  15. ;
  16. ; egg@dstos3.dsto.gov.au
  17. ; teg@bart.dsto.gov.au
  18. ;-----------------------------------------------------------------------
  19.  
  20. COMMENT  $
  21.  
  22.  
  23. This is a module implementing very basic mouse functions.
  24.  
  25. It does not support the full functionality of:
  26.  
  27.   SPLIT SCREENS
  28.   SCROLLED WINDOWS
  29.   VIRTUAL WINDOWS
  30.  
  31.           --------------------------------------
  32.  
  33.           MS Mouse Driver Functions
  34.  
  35.           Mouse Initialization                 0
  36.           Show Cursor                          1
  37.           Hide Cursor                          2
  38.           Get Mouse Position & Button Status   3
  39.           Set Mouse Cursor Position            4
  40.           Get Button Press Information         5
  41.           Get Button Release Information       6
  42.           Set Min/Max Horizontal Position      7
  43.           Set Min/Max Vertical Position        8
  44.           Define Graphics Cursor Block         9
  45.           Define Text Cursor                  10
  46.           Read Mouse Motion Counters          11
  47.           Define Event Handler                12
  48.           Light Pen Emulation Mode ON         13
  49.           Light Pen Emulation Mode OFF        14
  50.           Set Mouse Mickey/Pixel Ratio        15
  51.           Conditional Hide Cursor             16
  52.           Set Double-Speed Threshold          19
  53.           --------------------------------------
  54. $
  55.  
  56. include xlib.inc
  57. include xdetect.inc
  58.  
  59. .data
  60.  
  61. global   _MouseInstalled    :word
  62. global   _MouseHidden       :word
  63. global   _MouseButtonStatus :word
  64. global   _MouseX            :word
  65. global   _MouseY            :word
  66. global   _MouseFrozen       :byte
  67. global   _MouseColor        :byte
  68.  
  69. global   _x_define_mouse_cursor :proc
  70. global   _x_show_mouse          :proc
  71. global   _x_hide_mouse          :proc
  72. global   _x_mouse_remove        :proc
  73. global   _x_mouse_x_range       :proc
  74. global   _x_mouse_y_range       :proc
  75. global   _x_position_mouse      :proc
  76. global   _x_put_cursor          :proc
  77. global   _x_update_mouse        :proc
  78. global   _x_mouse_init          :proc
  79.  
  80.  
  81. ALIGN 2
  82.    InitMouseDef db 00000001b  ; Default mouse mask, note the reverse order
  83.         db 00000011b
  84.         db 00000111b
  85.         db 00001111b
  86.         db 00011111b
  87.         db 00111111b
  88.         db 01111111b
  89.         db 11111111b
  90.         db 00011100b
  91.         db 00111100b
  92.         db 01111100b
  93.         db 00000000b
  94.         db 00000000b
  95.         db 00000000b
  96.  
  97.     MouseMask          db 168 dup(?)
  98.     OldHandlerSeg      dw  ?
  99.     OldHandlerOffs     dw  ?
  100.     OldHandlerMask     dw  ?
  101.     OldX               dw  ?
  102.     OldY               dw  ?
  103.     OldScrnOffs        dw  ?
  104.  
  105.     BGSaveOffs         dw  0
  106.  
  107.    _MouseInstalled     dw 0     ; Flag indicating whether mouse is installed
  108.    _MouseHidden        dw 0     ; Flag indicating whether mouse is hidden
  109.    _MouseButtonStatus  dw 0     ; Holds current button press information
  110.    _MouseX             dw 0     ; Coords of cursor hot spot
  111.    _MouseY             dw 0
  112.    _MouseFrozen        db 0     ; Mouse motion enable/disable control
  113.    _MouseColor         db 0     ; Mouse cursor colour
  114.  
  115.    inhandler           db 0
  116. .code
  117.  
  118. ;----------------------------------------------------------------------
  119. ; Local function that updates the cursor position
  120. ;
  121. ; Destroys SI,DI,AX,BX
  122. ;
  123. ;----------------------------------------------------------------------
  124. proc update_cursor near
  125.    WaitVsyncStart
  126.  
  127.    mov di,[OldScrnOffs]             ; Delete cursor (restore old background)
  128.    mov ax,[OldY]
  129.    mov bx,[OldX]
  130.  
  131.    call restorebg
  132.  
  133.    mov si,[_VisiblePageOffs]        ; Save cursor background
  134.    mov ax,[_MouseY]
  135.    mov bx,[_MouseX]
  136.    mov [OldScrnOffs],si
  137.    mov [OldY],ax
  138.    mov [OldX],bx
  139.    call getbg
  140.  
  141.    push [_VisiblePageOffs]          ; Draw the cursor
  142.    mov  ax,[_ScrnPhysicalHeight]
  143.    push ax
  144.    mov  ax,0
  145.    push ax
  146.    push [OldY]
  147.    push [OldX]
  148.    call _x_put_cursor
  149.    add  sp,10
  150.    ret
  151. update_cursor endp
  152.  
  153.  
  154. ;----------------------------------------------------------------------
  155. ; x_mouse_init - Initialise Mode X mouse handler
  156. ;
  157. ; C Prototype
  158. ;
  159. ;  int x_mouse_init()
  160. ;
  161. ; This is the first function you must call before using any of the mouse
  162. ; functions
  163. ;
  164. ; WARNING: This function uses and updates "NonVisual_Offset" to allocate
  165. ;          video ram for the saved mouse background.
  166. ;
  167. ; This mouse code uses the fastest possible techniques to save and restore
  168. ; mouse backgrounds and to draw the mouse cursor.
  169. ;
  170. ; LIMITATIONS: No clipping is supported horizontally for the mouse cursor
  171. ;              No validity checking is performed for NonVisual_Offs
  172. ;
  173. ;
  174. ; **WARNING** Hide or freeze mouse while drawing using any of the other
  175. ;             Modules. VGA register settings are not preserved which will
  176. ;             result in unpredictable drawing behavior.
  177. ;             If you know the drawing will occur away from the mouse cursor
  178. ;             set MouseFrozen to TRUE (1), do your drawing then set it to
  179. ;             FALSE (0). Alternatively call "x_hide_mouse", perform your
  180. ;             drawing and then call "x_show_mouse"
  181. ;
  182. ;
  183. ; Written by Themie Gouthas
  184. ;----------------------------------------------------------------------
  185. _x_mouse_init proc
  186.      push  bp
  187.      mov   bp,sp
  188.  
  189.      cmp   [_MouseButtonCount],0  ; Dont initialize if mouse detection
  190.      jne   @@DontInitialize       ; or initialization function previously
  191.                   ;   called
  192.      xor   ax,ax                  ; FUNC 0: Mouse Initialization
  193.      int   33h                    ;
  194.      or    ax,ax                  ; Is there a mouse installed ?
  195.      jz    @@Done
  196.      mov   [_MouseButtonCount],bx ; Set the button count
  197.  
  198. @@DontInitialize:
  199.  
  200.      mov   [_MouseInstalled],ax
  201.      or    ax,ax                  ; Do we have an installed mouse driver ?
  202.      jz    @@Done                 ; Nop!
  203.  
  204.      mov   ax,[_NonVisual_Offs];  ; Allocate VRAM for saved background
  205.      mov   BGSaveOffs,ax
  206.  
  207.      add   ax,14*3
  208.      mov   [_NonVisual_Offs],ax   ; Update NonVisualOffset
  209.  
  210.      mov   ax,02                  ; FUNC 2: Hide Cursor
  211.      int   33h                    ;  (hide the mouse driver's default cursor)
  212.      mov   _MouseInstalled,TRUE   ; Indicate user mouse driver present
  213.  
  214.      mov   ax,07h                 ; FUNC 7:Set min/max horizontal position
  215.      mov   cx,0
  216.      mov   dx,[_ScrnPhysicalPixelWidth]
  217.      shl   dx,1                   ; Mult X by 2 as cursor steps by 2 pixels
  218.      int   33h                    ; 0 < X < _ScrnPhysicalPixelWidth
  219.  
  220.      mov   ax,08h                 ; FUNC 8:Set min/max vertical position
  221.      mov   cx,0
  222.      mov   dx,_ScrnPhysicalHeight
  223.      int   33h                    ; 0 < Y < _ScrnPhysicalHeight
  224.  
  225.      mov   ax,0fh                 ; FUNC 15: Mouse Hor/Vert resolution
  226.      mov   cx,4                   ; Horiz speed  >> Value => << Speed
  227.      mov   dx,8                   ; Vert Speed
  228.      int   33h
  229.  
  230.      mov   ax,3                   ; FUNC 3: Get mouse pos & button status
  231.      int   33h
  232.      mov   [_MouseY],dx
  233.      shr   cx,1
  234.      mov   [_MouseX],cx
  235.  
  236.      mov   ax,12                  ; FUNC 12: Define Event Handler
  237.      mov   bx,seg mouse_handler   ;  ES:DX -> Event handler
  238.      mov   es,bx
  239.      mov   dx,offset mouse_handler
  240.      mov   cx,1fh                 ;  Set handler for all events
  241.      int   33h
  242.  
  243.  
  244.  
  245.      mov   [_MouseHidden],TRUE    ; Mouse initially hidden
  246.  
  247.      push  ds                     ; Set the default cursor shape
  248.      mov   ax,offset InitMouseDef
  249.      push  ax
  250.      call  _x_define_mouse_cursor
  251.      add   sp,04h
  252.  
  253.      mov   ax,[_MouseInstalled]   ; Return MouseInstalled flag
  254. @@Done:
  255.      pop   bp
  256.      ret
  257. _x_mouse_init endp
  258.  
  259. ;----------------------------------------------------------------------
  260. ; x_mouse_window - Define a mouse window
  261. ;
  262. ; C Prototype
  263. ;
  264. ;  void x_mouse_window(int x0, int y0, int x1, int y1);
  265. ;
  266. ;
  267. ; Written by Themie Gouthas
  268. ;----------------------------------------------------------------------
  269. _x_mouse_window proc
  270. ARG x0:word,y0:word,x1:word,y1:word
  271.      push  bp
  272.      mov   bp,sp
  273.  
  274.      mov   ax,7       ; FUNC 7: Set X range
  275.      mov   cx,x0
  276.      shl   cx,1
  277.      mov   dx,x1
  278.      shl   dx,1
  279.      int   33h
  280.  
  281.      mov   ax,8       ; FUNC 8: Set Y range
  282.      mov   cx,y0
  283.      mov   dx,y1
  284.      int   33h
  285. _x_mouse_window endp
  286.  
  287.  
  288. ;----------------------------------------------------------------------
  289. ; x_define_mouse_cursor - Define a mouse cursor from an input bitmask
  290. ;
  291. ; C Prototype
  292. ;
  293. ;  void x_define_mouse_cursor(char far *MouseDef, unsigned char MouseColor)
  294. ;
  295. ; WARNING: This function assumes MouseDef points to 14 bytes.
  296. ;
  297. ; Note: Bit order is in reverse. ie bit 7 represents pixel 0 ..
  298. ;       bit 0 represents pixel 7 in each "MouseDef" byte.
  299. ;
  300. ; Written by Themie Gouthas
  301. ;----------------------------------------------------------------------
  302. _x_define_mouse_cursor proc
  303. ARG MouseDef:dword,MouseColor:byte
  304.      push  bp
  305.      mov   bp,sp
  306.  
  307.      cmp  [_MouseInstalled],FALSE   ; Check whether we have installed
  308.      je   @@Done                    ;  our mouse handler and leave if not
  309.  
  310.      mov  al,[MouseColor]           ; Set the mouse pointers color
  311.      mov  [_MouseColor],al
  312.  
  313.      push  si
  314.      push  di
  315.      push  ds
  316.      mov   ax,ds                ; ES:DI -> Stored plane mask for all
  317.      mov   es,ax                ;   pixel alignments of mouse cursor
  318.      mov   di,offset MouseMask
  319.      lds   si,MouseDef
  320.      xor   cl,cl                ; CL = current alignment (initially zero)
  321. @@AlignmentLoop:
  322.      push  si                   ; save MouseDef ptr for next alignment
  323.      mov   dh,14                ; Init Row counter to Cursor Height
  324. @@RowLoop:
  325.      lodsb                      ; Load first cursor def byte each bit
  326.                 ;  representing pixel in the row
  327.      xor   ah,ah                ; AH is the shift overflow byte
  328.      shl   ax,cl                ; Shift mask for current alignment
  329.  
  330.      mov   bl,al                ; store first three nibbles of ax into
  331.      and   bl,0fh               ;  consecutive bytes in the destination
  332.      mov   es:[di],bl           ;  buffer
  333.      inc   di
  334.      shr   al,4
  335.      stosw
  336.  
  337.      dec   dh                   ; Next row for this alignment if there
  338.      jnz   @@RowLoop            ;  are more to do
  339.  
  340.      pop   si                   ; point to the start of the cursor def.
  341.      inc   cl                   ; Select next pixel alignment
  342.      cmp   cl,4                 ; If there are more alignments to do
  343.      jne   @@AlignmentLoop      ;   then jump
  344.  
  345.      pop   ds
  346.      pop   di
  347.      pop   si
  348. @@Done:
  349.      pop   bp
  350.      ret
  351. _x_define_mouse_cursor endp
  352.  
  353.  
  354. ;----------------------------------------------------------------------
  355. ; x_show_mouse - Shows a previously hidden mouse cursor
  356. ;
  357. ; C Prototype
  358. ;
  359. ;  void x_show_mouse()
  360. ;
  361. ; Written by Themie Gouthas
  362. ;----------------------------------------------------------------------
  363. _x_show_mouse proc
  364.      push  bp
  365.      mov   bp,sp
  366.      cmp   [_MouseInstalled],FALSE  ; Make sure our handler is installed
  367.      je    @@Done
  368.      cmp   [_MouseHidden],FALSE     ; If not hidden then exit
  369.      je    @@Done
  370.      push  si
  371.      push  di
  372.  
  373.  
  374. @@WaitEndOfHandler:               ; Make sure handler not currently active
  375.      mov   cl,[inhandler]
  376.      or    cl,cl
  377.      jnz   @@WaitEndOfHandler
  378.  
  379.  
  380.      mov   si,[_VisiblePageOffs]  ; Save mouse background and pos details
  381.      mov   ax,[_MouseY]
  382.      mov   bx,[_MouseX]
  383.      mov   [OldScrnOffs],si
  384.      mov   [OldY],ax
  385.      mov   [OldX],bx
  386.      call  getbg
  387.  
  388.      push [_VisiblePageOffs]      ; Draw cursor
  389.      push [_ScrnLogicalHeight]
  390.      xor  ax,ax
  391.      push ax
  392.      push [OldY]
  393.      push [OldX]
  394.      call _x_put_cursor
  395.      add  sp,10
  396.  
  397.      mov   [_MouseHidden],FALSE   ; Indicate mouse cursor no longer hidden
  398.  
  399.      pop  di
  400.      pop  si
  401. @@Done:
  402.      pop   bp
  403.      ret
  404. _x_show_mouse endp
  405.  
  406.  
  407. ;----------------------------------------------------------------------
  408. ; x_hide_mouse - Hides a previously visible mouse cursor
  409. ;
  410. ; C Prototype
  411. ;
  412. ;  void x_hide_mouse()
  413. ;
  414. ; Written by Themie Gouthas
  415. ;----------------------------------------------------------------------
  416. _x_hide_mouse proc
  417.      push  bp
  418.      mov   bp,sp
  419.  
  420.      cmp   [_MouseInstalled],FALSE   ; Make sure our handler is installed
  421.      je    @@Done
  422.      cmp   [_MouseHidden],FALSE      ; If cursor is already hidden exit
  423.      jne   @@Done
  424.      push  si
  425.      push  di
  426.  
  427. @@WaitEndOfHandler:            ; Make sure handler not currently active
  428.      mov   cl,[inhandler]
  429.      or    cl,cl
  430.      jnz   @@WaitEndOfHandler
  431.  
  432.      mov   [_MouseHidden],TRUE       ; Delete mouse cursor
  433.      mov   di,[OldScrnOffs]
  434.      mov   ax,[OldY]
  435.      mov   bx,[OldX]
  436.      call  restorebg
  437.      pop   di
  438.      pop   si
  439. @@Done:
  440.      pop   bp
  441.      ret
  442. _x_hide_mouse endp
  443.  
  444.  
  445. ;----------------------------------------------------------------------
  446. ; x_remove_mouse - removes mouse handler
  447. ;
  448. ; C Prototype
  449. ;
  450. ;  void x_remove_mouse()
  451. ;
  452. ; NOTE: This function MUST be called before quitting the program if
  453. ;       a mouse handler has been installed
  454. ;
  455. ; Written by Themie Gouthas
  456. ;----------------------------------------------------------------------
  457. _x_mouse_remove proc
  458.     push  bp
  459.     mov   bp,sp
  460.     cmp   [_MouseInstalled],FALSE  ; Check whether we have installed
  461.     je    @@Done                   ;  our mouse handler
  462.     call  _x_hide_mouse
  463.     mov   ax,12                    ; FUNC 12: Install event handler
  464.     xor   cx,cx                    ; Disable all events
  465.     int   33h
  466.     mov   [_MouseInstalled],FALSE
  467. @@Done:
  468.     pop   bp
  469.     ret
  470. _x_mouse_remove endp
  471.  
  472.  
  473. ;----------------------------------------------------------------------
  474. ; x_position_mouse - Positions the mouse cursor at the specified location
  475. ;
  476. ; C Prototype
  477. ;
  478. ;  void x_position_mouse(int x, int y)
  479. ;
  480. ;
  481. ; Written by Themie Gouthas
  482. ;----------------------------------------------------------------------
  483. _x_position_mouse proc
  484. ARG  X:word,Y:word
  485.      push  bp
  486.      mov   bp,sp
  487.  
  488. @@WaitEndOfHandler:               ; Make sure handler not currently active
  489.      mov   bl,[inhandler]
  490.  
  491.      or    bl,bl
  492.      jnz   @@WaitEndOfHandler
  493.  
  494.      mov   ax,4
  495.      mov   cx,X
  496.      mov   dx,Y
  497.      mov   [_MouseX],cx
  498.      mov   [_MouseY],dx
  499.      shl   cx,1
  500.  
  501.      mov   [inhandler],1
  502.      int   33h
  503.  
  504.      ; The handler doesnt get called so need
  505.      ; to update manually;
  506.  
  507.      cmp   [_MouseHidden],FALSE
  508.      jne   @@NotVisible
  509.      push  di si
  510.      call  update_cursor
  511.      pop   si di
  512.  
  513. @@NotVisible:
  514.      mov   [inhandler],0
  515.      pop   bp
  516.      ret
  517. _x_position_mouse endp
  518.  
  519. ;----------------------------------------------------------------------
  520. ; x_update_mouse - Forces the mouse position to be updated and cursor
  521. ;                  to be redrawn.
  522. ;
  523. ; C Prototype
  524. ;
  525. ;  void x_update_mouse()
  526. ;
  527. ; Note this function is useful when you have set "MouseFrozen" to true.
  528. ; Allows the cursor position to be updated manually rather than
  529. ; automatically by the installed handler.
  530. ;
  531. ;
  532. ; Written by Themie Gouthas
  533. ;----------------------------------------------------------------------
  534. _x_update_mouse proc
  535.      push  bp
  536.      mov   bp,sp
  537.      cmp   [_MouseInstalled],FALSE   ; Make sure our handler is installed
  538.      je    @@Done
  539.      cmp   [_MouseHidden],FALSE      ; If cursor is already hidden exit
  540.      jne   @@Done
  541.      push  si
  542.      push  di
  543.      mov   ax,03h                 ; FUNC 3: get cursor pos / button status
  544.      int   33h                    ; Update position variables first
  545.      shr   cx,1
  546.      mov   [_MouseX],cx
  547.      mov   [_MouseY],dx
  548.      mov   [_MouseButtonStatus],bx    ; Update button status
  549.      call  update_cursor
  550.      pop   di
  551.      pop   si
  552. @@Done:
  553.      pop   bp
  554.      ret
  555. _x_update_mouse endp
  556.  
  557.  
  558. ;----------------------------------------------------------------------
  559. ; x_put_cursor - Draws the mouse cursor
  560. ;
  561. ; C Prototype
  562. ;
  563. ; void x_put_cursor(int X, int Y, int TopClip, int BottomClip, WORD ScrnOffs)
  564. ;
  565. ;
  566. ; Written by Themie Gouthas
  567. ;----------------------------------------------------------------------
  568. ALIGN 2
  569. _x_put_cursor  proc
  570. ARG X:word,Y:word,TopClip,BottomClip,ScrnOffs
  571. LOCAL Height,TopRow,NextLineIncr:word=LocalStk
  572.     push  bp
  573.         mov   bp,sp
  574.     sub   sp,LocalStk                 ; Create space for local variables
  575.         push  si
  576.     push  di
  577.     push  ds
  578.     mov   ax,@data
  579.     mov   ds,ax
  580.     cld
  581.  
  582.     mov   ax,14                   ; Get image height and save in AX
  583.     mov   bx,Y
  584.     ; cx = top Row
  585.  
  586.     ;;;;; CLIP PROCESSING FOR TOP CLIP BORDER ;;;;;;;;;;;;;;;;;;;;;
  587.  
  588.     mov   dx,[TopClip]            ; Compare u.l. Y coord with Top
  589.     sub   dx,bx                   ; clipping border
  590.     jle   @@NotTopClip            ; jump if  not clipped from above
  591.     cmp   dx,ax
  592.     jnl   @@NotVisible            ; jump if  is completely obscured
  593.     mov   cx,dx
  594.     sub   ax,dx
  595.     add   bx,dx
  596.     jmp   short @@VertClipDone
  597.  
  598.     ;;;; EXIT FOR COMPLETELY OBSCURED  ;;;;;;;;;;;;;;;;;;;;;;
  599.  
  600. @@NotVisible:
  601.     pop   ds
  602.     pop   di                          ; restore registers
  603.     pop   si
  604.     mov   sp,bp                       ; dealloc local variables
  605.     pop   bp
  606.     ret
  607.  
  608.     ;;;;; CLIP PROCESSING FOR BOTTOM CLIP BORDER ;;;;;;;;;;;;;;;;;;;
  609.  
  610. @@NotTopClip:
  611.     mov   dx,[BottomClip]
  612.     sub   dx,bx
  613.     js    @@NotVisible
  614.     mov   cx,0
  615.     cmp   dx,ax
  616.     jg    @@VertClipDone
  617.     inc   dx
  618.     mov   ax,dx
  619.  
  620. @@VertClipDone:
  621.  
  622.     mov   [Height],ax
  623.     mov   [TopRow],cx
  624.  
  625.         mov   ax,SCREEN_SEG               ; Point es to VGA segment
  626.     mov   es,ax
  627.  
  628.     mov   ax,bx
  629.     mov   cx,[_ScrnLogicalByteWidth]  ; Find required screen address
  630.     mul   cx
  631.     mov   di,ax
  632.  
  633.     sub   cx,3                        ; Distance to next screen row
  634.     mov   [NextLineIncr],cx
  635.  
  636.  
  637.     mov   cx,[X]
  638.     mov   bx,cx
  639.     shr   cx,2
  640.     add   di,cx
  641.     and   bx,3
  642.     add   di,[ScrnOffs]
  643.  
  644.     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  645.  
  646.  
  647.     mov   ax,42
  648.     mul   bx
  649.     mov   si,offset MouseMask
  650.     add   si,ax
  651.  
  652.     mov   ax,3                        ; Increment DS:BX and DS:SI to
  653.     mul   [TopRow]                    ;  been clipped by the top border
  654.     add   si,ax                       ; by the L.H.S border
  655.  
  656.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  657.     mov   al,MAP_MASK                 ; in preperation for masking data
  658.     out   dx,al
  659.     inc   dx                          ; Point dx to SC data register
  660.     mov   ah,byte ptr [Height]        ; AH = Scanline loop counter
  661.     mov   bl,[_MouseColor]
  662. @@RowLoop:
  663.     mov   cx,3                        ; Width in bytes across
  664. @@ColLoop:
  665.     lodsb                             ; load plane mask and set MAP MASK
  666.     out   dx,al
  667.     mov   es:[di],bl                  ; store color to specified planes
  668.     inc   di
  669.     loop  @@ColLoop
  670.  
  671.     add   di,[NextLineIncr]
  672.     dec   ah
  673.     jnz   @@RowLoop
  674.  
  675.     pop   ds
  676.         pop   di                          ; restore registers
  677.         pop   si
  678.         mov   sp,bp                       ; dealloc local variables
  679.         pop   bp
  680.         ret
  681. _x_put_cursor  endp
  682.  
  683.  
  684. ;----------------------------------------------------------------------
  685. ; getbg - saves cursor background
  686. ;
  687. ; C Prototype
  688. ;
  689. ; local function using register parameters
  690. ;
  691. ; si = screen offset
  692. ; ax  = y
  693. ; bx  = x
  694. ;
  695. ; Written by Themie Gouthas
  696. ;----------------------------------------------------------------------
  697. ALIGN 2
  698. getbg  proc near
  699.  
  700.     push  bp
  701.     mov   bp,sp
  702.     push  ds
  703.     cld
  704.  
  705.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  706.     mul   cx                          ;  width then adding screen offset
  707.     add   si,ax                       ; Add Dest Screen Row to di
  708.     sub   cx,3
  709.     shr   bx,2
  710.     add   si,bx
  711.         mov   bx,cx
  712.  
  713.         mov   di,BGSaveOffs
  714.         mov   ax,SCREEN_SEG               ; Point es to VGA segment
  715.     mov   es,ax
  716.     mov   ds,ax
  717.  
  718.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  719.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  720.     out   dx,ax
  721.  
  722.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  723.     mov   al,MAP_MASK           ; in preperation for masking data
  724.         out   dx,al
  725.     inc   dx
  726.     mov   al,0fh
  727.     out   dx,al
  728.  
  729.     mov   cx,14
  730. @@Loop:
  731.     movsb
  732.     movsb
  733.     movsb
  734.     add si,bx
  735.     loop @@Loop
  736.  
  737. mov     dx,GC_INDEX+1 ;restore the bit mask to its default,
  738.         mov     al,0ffh       ; which selects all bits from the CPU
  739.         out     dx,al         ; and none from the latches (the GC
  740.                               ; Index still points to Bit Mask)
  741.  
  742.     pop   ds
  743.         mov   sp,bp                       ; dealloc local variables
  744.         pop   bp
  745.         ret
  746. getbg  endp
  747.  
  748. ;----------------------------------------------------------------------
  749. ; restorebg - restores cursor background
  750. ;
  751. ; C Prototype
  752. ;
  753. ; local function using register parameters
  754. ;
  755. ; di = screen offset
  756. ; ax  = y
  757. ; bx  = x
  758. ;
  759. ; Written by Themie Gouthas
  760. ;----------------------------------------------------------------------
  761. ALIGN 2
  762. restorebg  proc near
  763. ;di = scrn offs
  764. ;ax  = y
  765. ;bx  = x
  766.     push  bp
  767.     mov   bp,sp
  768.     push  ds
  769.     cld
  770.  
  771.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  772.     mul   cx                          ;  width then adding screen offset
  773.     add   di,ax                       ; Add Dest Screen Row to di
  774.     sub   cx,3
  775.     shr   bx,2
  776.     add   di,bx
  777.     mov   si,BGSaveOffs
  778.         mov   ax,SCREEN_SEG               ; Point es to VGA segment
  779.     mov   es,ax
  780.     mov   ds,ax
  781.  
  782.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  783.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  784.     out   dx,ax
  785.  
  786.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  787.     mov   al,MAP_MASK                 ; in preperation for masking data
  788.     out   dx,al
  789.     inc   dx
  790.     mov   al,0fh
  791.     out   dx,al
  792.  
  793.     mov   bx,cx
  794.     mov   cx,14
  795. @@Loop:
  796.     movsb
  797.     movsb
  798.     movsb
  799.     add di,bx
  800.     loop @@Loop
  801.     mov  dx,GC_INDEX+1 ;restore the bit mask to its default,
  802.     mov  al,0ffh       ; which selects all bits from the CPU
  803.     out  dx,al         ; and none from the latches (the GC
  804.                ; Index still points to Bit Mask)
  805.     pop   ds
  806.         pop   bp
  807.         ret
  808. restorebg  endp
  809.  
  810.  
  811.  
  812. ;********************** The Mouse event handler *************************
  813.  
  814. ALIGN 2
  815. mouse_handler proc far
  816.    push  bp
  817.    mov   bp,sp
  818.    push  ds
  819.  
  820.    mov   di,@data                   ; Make sure DS points to data segment
  821.    mov   ds,di
  822.    cmp   [inhandler],1
  823.    jne   @@NotActive
  824.    pop   ds
  825.    pop   bp
  826.    ret
  827.  
  828. @@NotActive:
  829.    mov   [inhandler],1
  830.    mov   [_MouseButtonStatus],bx    ; Update button status
  831.    test  ax,1                       ; Is this a motion event ?
  832.    jz    @@Done                     ; No Jump
  833.  
  834.    shr  cx,1                        ; convert X coord to pixel coords
  835.    mov  [_MouseX],cx                ; save mouse position
  836.    mov  [_MouseY],dx
  837.  
  838.    cmp  [_MouseHidden],TRUE         ; If mouse hidden dont bother drawing
  839.    je   @@Done
  840.  
  841.    cmp  [_MouseFrozen],TRUE         ; If mouse hidden dont bother drawing
  842.    je   @@Done
  843.  
  844.    call update_cursor
  845. @@Done:
  846.    mov  [inhandler],0
  847.    pop  ds
  848.    pop  bp
  849.    ret
  850. mouse_handler endp
  851.  
  852.  
  853. end